import javax.swing.tree.TreeNode;

/*
 * @lc app=leetcode.cn id=404 lang=java
 *
 * [404] 左叶子之和
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    int res=0;
    public int sumOfLeftLeaves(TreeNode root) {
        if(root==null) return 0;
        int value=0;
        if(root.left!=null&&root.left.left==null&&root.left.right==null){
            value=root.left.val;//实际处理的左节点
        }
        int left=sumOfLeftLeaves(root.left);//左子树的sum
        int right=sumOfLeftLeaves(root.right);//右子树的sum
        res=value+left+right;
        return  res;
    }
}
// @lc code=end

